package bankDB;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DataBaseConnection {
Connection con;
private String DatabaseUrl="jdbc:oracle:thin:@localhost:1521:xe";
private String DatabaseName="worktest";
private String DatabasePassword="worktest";
private String DatabaseDriver="oracle.jdbc.driver.OracleDriver";
public DataBaseConnection() throws Exception {
try {
	Class.forName(DatabaseDriver).newInstance();
	//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
	con=DriverManager.getConnection(DatabaseUrl, DatabaseName, DatabasePassword);
	
} catch (InstantiationException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	throw new Exception("Couldn't open connection to database: " + e.getMessage());
} catch (IllegalAccessException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	throw new Exception("Couldn't open connection to database: " + e.getMessage());
} catch (ClassNotFoundException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
	throw new Exception("Couldn't open connection to database: " + e.getMessage());
}
}

protected synchronized void releaseConnection() {
	closeConnection();
}
public void closeConnection () {
	try {
		con.close();
	} catch (SQLException ex) {
		System.out.println(ex.getMessage());
	}
}

}
